package com.itheima.zuoye.zuoye1;

public class Acc implements Runnable{
    int sum = 100;


    @Override
    public void run() {
        while (true){
            if (getgift()){
               break;
            }

        }

    }


    private synchronized boolean getgift(){
        if (sum>10){
            System.out.println(Thread.currentThread().getName()+"正在发送第"+sum+"个礼物");
            sum--;
            try {
                Thread.sleep(10);
            }catch (InterruptedException e){
                throw new RuntimeException(e);
            }
            return false;
        }else {
            System.out.println(Thread.currentThread().getName()+"礼物已发完");
            return true;
        }
    }

}
